/*
 * edbd_extcall.h - edbd module external call header file
 * Clunix, cezanne@clunix.com, 2005.7
 *
 * $Id: edbd_extcall.h,v 1.3 2007/10/02 07:57:06 cezanne Exp $
 *
 * Copyright (c) 2001-2005 by Clunix Inc. All Rights Reserved.
 */

#ifndef _EDBD_EXTCALL_H_
#define _EDBD_EXTCALL_H_

#include "libsr.h"
#include "libebc.h"

#ifndef _WIN32
#define EDBFUNC_API
#else
#ifdef __cplusplus
#define EDBFUNC_API	extern "C" __declspec(dllexport)
#else
#define EDBFUNC_API	__declspec(dllexport)
#endif
#endif

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
	ECMBOOL	(*authenticate)(const char *username, const char *passwd);
	ECMBOOL (*is_admin)(const char *username);
} edbd_authfuncs_t;

void edbd_reg_auth(edbd_authfuncs_t *funcs);

ECMBOOL edbd_authenticate(const char *username, const char *passwd);

sr_t *edbd_xecreate(sr_t *sr_HMS, const char *xe_name, srt_t srt);
ECMBOOL edbd_xedelete(sr_t *sr_xe, ECMBOOL force);
sr_t *edbd_xeappend(sr_t *sr_HMS, sr_t *sr_xe);
sr_t *xe_create(srt_t srt);
ECMBOOL edbd_aexece(ebc_ndid_t ndid, int timeout, int *pexitcode, const char *const asrv_arr[], const char *const env_arr[], const sr_t *sr);
ECMBOOL edbd_aexece_as_user(ebc_ndid_t ndid, int timeout, int *pexitcode, const char *const asrv_arr[], const char *const env_arr[], const char *workdir, const sr_t *sr, const char *username, const char *passwd);
ECMBOOL edbd_aexec(ebc_ndid_t ndid, int timeout, int *pexitcode, char *const asrv_arr[], const char *workdir, const sr_t *sr);
ECMBOOL edbd_exec(ebc_ndid_t ndid, int timeout, int *pexitcode, const char *program, const char *workdir, const sr_t *sr, ...);
ECMBOOL edbd_sexec(ebc_ndid_t ndid, int timeout, int *pexitcode, const char *command, const char *workdir, const sr_t *sr);
ECMBOOL edbd_sexece(ebc_ndid_t ndid, int timeout, int *pexitcode, const char *command, const char *env, const char *workdir, const sr_t *sr);
ECMBOOL edbd_sexece_as_user(ebc_ndid_t ndid, int timeout, int *pexitcode, const char *command, const char *env, const char *workdir, const sr_t *sr, const char *username, const char *passwd);

const char *edbd_username(void);
const ebc_addr_t *edbd_useraddr(void);

sr_t *edbd_ebc_call(const char *target, sr_t *sca);
sr_t *edbd_ebc_call_timeout(const char *target, sr_t *sca, int timeout);
ECMBOOL edbd_ebc_call_oneway(const char *target, sr_t *sca);
void edbd_error(const char *format, ...);
void edbd_verbose(const char *format, ...);

char *edbd_encrypt(const char *data, ecm_size_t len);
char *edbd_decrypt(const char *encdata, ecm_size_t len);

sr_t *edbd_pin_sr(const sr_t *sr);
void edbd_unpin_sr(sr_t *sr);
void edbd_clear_pins(void);

void edbd_lock(const char *lockname);
void edbd_unlock(const char *lockname);

#ifdef ECM_DEBUG
void edbd_set_dbgset(const char *);
void edbd_debug(const char *dbgset, const char *file, int line, const char *fmt, ...);

#ifndef _WIN32
#define EDBD_DEBUG(dbgset, fmt, ...)	edbd_debug(dbgset, __FILE__, __LINE__, fmt, ## __VA_ARGS__)
#else
void EDBD_DEBUG(const char *dbgset, const char *format, ...);
#endif

void edbd_mtrace(int level);
void edbd_muntrace(void);
void edbd_mtrace_clear(void);
void edbd_mtrace_report(void);

#else

#ifndef _WIN32
#define EDBD_DEBUG(dbgset, fmt, ...)	do {} while (0)
#else
void EDBD_DEBUG(const char *dbgset, const char *format, ...);
#endif

#endif

#ifdef __cplusplus
}
#endif

#endif
